package com.ds.infrastructure.hyperspace.container.internal.operator;

/**
 * usage eg:
 * [END_WITH, expectValue|expectValue1]
 *
 * @author  Weishaoying
 */
public class EndWithOperator extends AbstractOperator {

    private static final int AGRS_LENGTH = 1;

    @Override
    public String compute(String inputValue, String[] args) {
        if (inputValue == null) {
            return null;
        }
        if (args.length == AGRS_LENGTH) {
            return inputValue.endsWith(args[0]) ? inputValue : null;
        }

        for (String expectValue : args) {
            if (inputValue.endsWith(expectValue)) {
                return inputValue;
            }
        }
        return null;
    }

    @Override
    public String getOperatorName() {
        return "END_WITH";
    }

    @Override
    public int getOperatorArgsLength() {
        return AGRS_LENGTH;
    }
}
